/*
 * @Author: Jiraiya
 * @Date: 2020-05-26 16:38:48
 * @LastEditors: Jiraiya
 * @LastEditTime: 2020-05-26 16:39:08
 * @Description: 
 */ 
export default function combineReducers(reducers){
    const reducerKeys = Object.keys(reducers);
    return function combination(state={}, action){
        const nextState = {};
        for(let i=0; i<reducerKeys.length; i++){
            const key = reducerKeys[i];
            const reducer = reducers[key];
            const previouStateForKey = state[key];
            const nextStateForKey = reducer(previouStateForKey, action);

            nextState[key] = nextStateForKey;
        }
        return nextState;
    }
}